package com.ucenter.server.user.controller;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.system.comm.model.Orderby;
import com.system.comm.utils.FrameJsonUtil;
import com.system.comm.utils.FrameStringUtil;
import com.system.handle.model.ResponseCode;
import com.system.handle.model.ResponseFrame;
import com.ucenter.server.user.pojo.UserLog;
import com.ucenter.server.user.service.UserLogService;

/**
 * user_log的Controller
 * @author autoCode
 * @date 2018-02-06 15:18:19
 * @version V1.0.0
 */
@RestController
public class UserLogController {

	private static final Logger LOGGER = LoggerFactory.getLogger(UserLogController.class);

	@Autowired
	private UserLogService userLogService;
	
	@RequestMapping(name = "获取详细信息", value = "/userLog/get")
	public ResponseFrame get(String ulId) {
		try {
			ResponseFrame frame = new ResponseFrame();
			frame.setBody(userLogService.get(ulId));
			frame.setCode(ResponseCode.SUCC.getCode());
			return frame;
		} catch (Exception e) {
			LOGGER.error("处理业务异常: " + e.getMessage(), e);
			return new ResponseFrame(ResponseCode.SERVER_ERROR);
		}
	}

	@RequestMapping(name = "分页查询信息", value = "/userLog/pageQuery")
	public ResponseFrame pageQuery(UserLog userLog, String orderby) {
		try {
			if(FrameStringUtil.isNotEmpty(orderby)) {
				List<Orderby> orderbys = FrameJsonUtil.toList(orderby, Orderby.class);
				userLog.setOrderbys(orderbys);
			}
			ResponseFrame frame = userLogService.pageQuery(userLog);
			return frame;
		} catch (Exception e) {
			LOGGER.error("处理业务异常: " + e.getMessage(), e);
			return new ResponseFrame(ResponseCode.SERVER_ERROR);
		}
	}

	@RequestMapping(name = "根据主键删除", value = "/userLog/delete")
	public ResponseFrame delete(String ulId) {
		try {
			ResponseFrame frame = userLogService.delete(ulId);
			return frame;
		} catch (Exception e) {
			LOGGER.error("处理业务异常: " + e.getMessage(), e);
			return new ResponseFrame(ResponseCode.SERVER_ERROR);
		}
	}
}